package com.dong.rabbitmq.direct;

import com.dong.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import static com.dong.rabbitmq.common.Constant.*;

/**
 * @author dongjian
 * Direct Exchange 直接交换机
 * 消费者01
 */
public class ReceiveLogsDirect02 {

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtil.getChannel();
        channel.exchangeDeclare(DIRECT_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        channel.queueDeclare(DIRECT_QUEUE_NAME_DISK, false, false, false, null);
        channel.queueBind(DIRECT_QUEUE_NAME_DISK, DIRECT_EXCHANGE_NAME, DIRECT_ROUTING_NAME_ERROR);
        System.out.println("消费者02,等待接收消息，将消息内容打印到屏幕上......");
        // 消息处理
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("消费者02,控制台打印接收到的消息=====>" + new String(message.getBody(), "UTF-8"));
        };
        channel.basicConsume(DIRECT_QUEUE_NAME_DISK, true, deliverCallback, consumerTag -> {
        });
    }
}
